package org.jeecg.modules.demo.zjzx.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoDict;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.demo.zjzx.entity.ZwglRiceGrowth;
import org.jeecg.modules.demo.zjzx.service.IZwglRiceGrowthService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.modules.demo.zjzx.vo.SimulatedGrowthVo;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.apache.shiro.authz.annotation.RequiresPermissions;

 /**
 * @Description: zwgl_rice_growth
 * @Author: jeecg-boot
 * @Date:   2023-04-20
 * @Version: V1.0
 */
@Api(tags="zwgl_rice_growth")
@RestController
@RequestMapping("/zjzx/zwglRiceGrowth")
@Slf4j
public class ZwglRiceGrowthController extends JeecgController<ZwglRiceGrowth, IZwglRiceGrowthService> {
	@Autowired
	private IZwglRiceGrowthService zwglRiceGrowthService;

	/**
	 * 分页列表查询
	 *
	 * @param zwglRiceGrowth
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "zwgl_rice_growth-分页列表查询")
	@ApiOperation(value = "水稻生长模拟-分页列表查询", notes = "水稻生长模拟-分页列表查询")
	@GetMapping(value = "/list")
	public Result<IPage<ZwglRiceGrowth>> queryPageList(ZwglRiceGrowth zwglRiceGrowth,
													   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
													   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
													   HttpServletRequest req) {
		QueryWrapper<ZwglRiceGrowth> queryWrapper = QueryGenerator.initQueryWrapper(zwglRiceGrowth, req.getParameterMap());
		queryWrapper.orderByAsc("time_date");
		Page<ZwglRiceGrowth> page = new Page<ZwglRiceGrowth>(pageNo, pageSize);
		IPage<ZwglRiceGrowth> pageList = zwglRiceGrowthService.page(page, queryWrapper);
		return Result.OK(pageList);
	}
	 @ApiOperation(value = "水稻生长模拟-最终结果", notes = "水稻生长模拟-最终结果")
	 @GetMapping(value = "/finalResult")
	 public Result finalResult() {
		 ZwglRiceGrowth zwglRiceGrowth=   zwglRiceGrowthService.finalResult();
		 return Result.OK(zwglRiceGrowth);
	 }
	 @ApiOperation(value = "水稻生长模拟-最终结果", notes = "水稻生长模拟-最终结果")
	 @GetMapping(value = "/myList")
	 public Result myList() {
		 List<ZwglRiceGrowth> list = zwglRiceGrowthService.myList();
		 return Result.OK(list);
	 }

	 //@AutoLog(value = "水稻生长模拟-分页列表查询")
	 @ApiOperation(value = "水稻生长模拟-分页列表查询", notes = "水稻生长模拟-分页列表查询")
	 @PostMapping(value = "/simulatedGrowth")
	 public Result simulatedGrowth(@RequestBody SimulatedGrowthVo simulatedGrowthVo) throws Exception {
		 zwglRiceGrowthService.simulatedGrowth(simulatedGrowthVo);
		 return Result.OK();
	 }

	 /**
	  * 添加
	  *
	  * @param zwglRiceGrowth
	  * @return
	  */
	 @AutoLog(value = "水稻生长模拟-添加")
	 @ApiOperation(value = "水稻生长模拟-添加", notes = "水稻生长模拟-添加")
	 //@RequiresPermissions("com.nfyszny.zwgl:zwgl_rice_growth:add")
	 @PostMapping(value = "/add")
	 public Result<String> add(@RequestBody ZwglRiceGrowth zwglRiceGrowth) {
		 zwglRiceGrowthService.save(zwglRiceGrowth);
		 return Result.OK("添加成功！");
	 }

	 /**
	  * 编辑
	  *
	  * @param zwglRiceGrowth
	  * @return
	  */
	 @AutoLog(value = "水稻生长模拟-编辑")
	 @ApiOperation(value = "水稻生长模拟-编辑", notes = "水稻生长模拟-编辑")
	 //@RequiresPermissions("com.nfyszny.zwgl:zwgl_rice_growth:edit")
	 @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
	 public Result<String> edit(@RequestBody ZwglRiceGrowth zwglRiceGrowth) {
		 zwglRiceGrowthService.updateById(zwglRiceGrowth);
		 return Result.OK("编辑成功!");
	 }

	 /**
	  * 通过id删除
	  *
	  * @param id
	  * @return
	  */
	 @AutoLog(value = "水稻生长模拟-通过id删除")
	 @ApiOperation(value = "水稻生长模拟-通过id删除", notes = "水稻生长模拟-通过id删除")
	 //@RequiresPermissions("com.nfyszny.zwgl:zwgl_rice_growth:delete")
	 @DeleteMapping(value = "/delete")
	 public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
		 zwglRiceGrowthService.removeById(id);
		 return Result.OK("删除成功!");
	 }

	 /**
	  * 批量删除
	  *
	  * @param ids
	  * @return
	  */
	 @AutoLog(value = "水稻生长模拟-批量删除")
	 @ApiOperation(value = "水稻生长模拟-批量删除", notes = "水稻生长模拟-批量删除")
	 //@RequiresPermissions("com.nfyszny.zwgl:zwgl_rice_growth:deleteBatch")
	 @DeleteMapping(value = "/deleteBatch")
	 public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
		 this.zwglRiceGrowthService.removeByIds(Arrays.asList(ids.split(",")));
		 return Result.OK("批量删除成功!");
	 }

	 /**
	  * 通过id查询
	  *
	  * @param id
	  * @return
	  */
	 //@AutoLog(value = "水稻生长模拟-通过id查询")
	 @ApiOperation(value = "水稻生长模拟-通过id查询", notes = "水稻生长模拟-通过id查询")
	 @GetMapping(value = "/queryById")
	 public Result<ZwglRiceGrowth> queryById(@RequestParam(name = "id", required = true) String id) {
		 ZwglRiceGrowth zwglRiceGrowth = zwglRiceGrowthService.getById(id);
		 if (zwglRiceGrowth == null) {
			 return Result.error("未找到对应数据");
		 }
		 return Result.OK(zwglRiceGrowth);
	 }

	 /**
	  * 导出excel
	  *
	  * @param request
	  * @param zwglRiceGrowth
	  */
	 //@RequiresPermissions("com.nfyszny.zwgl:zwgl_rice_growth:exportXls")
	 @RequestMapping(value = "/exportXls")
	 public ModelAndView exportXls(HttpServletRequest request, ZwglRiceGrowth zwglRiceGrowth) {
		 return super.exportXls(request, zwglRiceGrowth, ZwglRiceGrowth.class, "水稻生长模拟");
	 }

	 /**
	  * 通过excel导入数据
	  *
	  * @param request
	  * @param response
	  * @return
	  */
	 //@RequiresPermissions("zwgl_rice_growth:importExcel")
	 @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
	 public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
		 return super.importExcel(request, response, ZwglRiceGrowth.class);
	 }



	 @GetMapping(value = "/getmoni")
	 @AutoDict
	 public Result moni(@RequestParam(name = "time_date", required = false) String timeDate) throws Exception {

		 return zwglRiceGrowthService.nianfen(timeDate);
	 }
	 @GetMapping(value = "/getmonia")
	 @AutoDict
	 public Result monia(@RequestParam(name = "time_date", required = false) String timeDate) throws Exception {

		 return zwglRiceGrowthService.nianfena(timeDate);
	 }
	 @GetMapping(value = "/getmoninf")
	 @AutoDict
	 public Result getmoninf() throws Exception {

		 return zwglRiceGrowthService.moninf();
	 }
}
